﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;


namespace Zero.CheckPoint
{
    public class PlayerController : MonoBehaviour
    {
        public float moveSpeed = 8f;
        public float jumpForce = 5f;
        public CheckPoint checkPoint;

        private Rigidbody2D _rigidbody2D;

        private void Start()
        {
            _rigidbody2D = GetComponent<Rigidbody2D>();
        }

        private void Update()
        {
            var h = Input.GetAxis("Horizontal");
            var v = Input.GetAxis("Vertical");
            _rigidbody2D.velocity = new Vector2(h * moveSpeed, _rigidbody2D.velocity.y);

            if (Input.GetKeyDown(KeyCode.Space)) _rigidbody2D.AddForce(Vector2.up * jumpForce, ForceMode2D.Impulse);

            if (Input.GetKeyDown(KeyCode.R) && checkPoint != null) checkPoint.Spawn(gameObject);
        }
    }
}